from selenium import webdriver
from selenium.webdriver.common.by import By
import  time


driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

driver.find_element(By.LINK_TEXT,'新闻').click()
driver.find_element(By.PARTIAL_LINK_TEXT,'hao').click()
time.sleep(2)
print(driver.title)


#找到第二个窗口 新闻窗口
a=driver.window_handles[1]
#切换到新闻窗口
time.sleep(2)
driver.switch_to.window(a)
print(driver.title)

time.sleep(2)
#切换到hao123窗口
b=driver.window_handles[2]
driver.switch_to.window(b)
print(driver.title)

time.sleep(2)
#切换到初页面
c=driver.window_handles[0]
driver.switch_to.window(c)
time.sleep(2)
print(driver.title)

time.sleep(2)
driver.quit()





